public class Test19 {
    public static TreeNode mirror(TreeNode node){
        if(node == null) return null;
        mirror(node.left);
        mirror(node.right);
        swap(node);
        return node;

    }
    public static  void swap(TreeNode node){
        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;
    }

    public static void printTreeNode(TreeNode node){
        if (node != null) {
            System.out.print(node.val + " ");
            printTreeNode(node.left);
            printTreeNode(node.right);
        }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode();
        root.val = 1;
        root.left = new TreeNode();
        root.left.val = 2;
        root.right = new TreeNode();
        root.right.val = 3;
        root.left.left = new TreeNode();
        root.left.left.val = 4;
        root.left.right = new TreeNode();
        root.left.right.val = 5;
        root.right.left = new TreeNode();
        root.right.left.val = 6;
        root.right.right = new TreeNode();
        root.right.right.val = 7;
        printTreeNode(root);
        System.out.println();
        TreeNode mirror = mirror(root);
        printTreeNode(mirror);

    }
}
